FROM ambari_base:7
MAINTAINER Aaron

# add ambari repo
ADD ambari.repo /etc/yum.repos.d/

# initscripts (service wrapper for servicectl) is need othewise the Ambari is unable to start postgresql
RUN yum install -y ambari-server && yum clean all

# add ambari shell to the image so new users don't need the 1GB java image
#RUN curl -o /tmp/ambari-shell.jar https://s3-eu-west-1.amazonaws.com/maven.sequenceiq.com/releases/com/sequenceiq/ambari-shell/0.1.25/ambari-shell-0.1.25.jar
ADD ambari-shell.jar /opt/
ADD shell/install-cluster.sh /opt/
ADD shell/wait-for-host-number.sh /opt/
ADD shell/ambari-shell.sh /opt/

ENV PLUGIN_PATH /plugins
WORKDIR /opt

ADD init/init-server.sh /opt/ambari-server/init-server.sh
RUN chmod u+x /opt/ambari-server/init-server.sh

# add mysql and psql connectors to ambari-server so it can be downloaded by services (e.g.: Ranger)
ADD http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.49.tar.gz /var/lib/ambari-server/resources/mysql-jdbc-driver.jar
ADD https://jdbc.postgresql.org/download/postgresql-42.3.1.jar /var/lib/ambari-server/resources/postgres-jdbc-driver.jar

ADD init/ambari-server.service /etc/systemd/system/ambari-server.service
RUN systemctl enable ambari-server

RUN echo DefaultEnvironment=\"JAVA_HOME=$JAVA_HOME\" >> /etc/systemd/system.conf

EXPOSE 8080
HEALTHCHECK --interval=30s --timeout=5s CMD systemctl status ambari-server | grep active || exit 1

ADD ambari-flink-service.zip /opt/
RUN unzip /opt/ambari-flink-service.zip \ 
  && mv ambari-flink-service /var/lib/ambari-server/resources/stacks/HDP/3.1/services/FLINK \
  && rm -f ambari-flink-service.zip \
  && groupadd -r flink && useradd -g flink flink 
